<?php

namespace App\Controller\Admin\Content;

use App\Controller\Admin\BaseController;
use App\Service\Content\AdService;
use App\Validator\Admin\Content\AdValidator;
use Hyperf\Di\Annotation\Inject;

class AdController extends BaseController
{

    #[Inject]
    protected AdValidator $adValidator;

    #[Inject]
    protected AdService $adService;

    public function pageList()
    {

    }

    public function all()
    {
        $params = $this->allParams();
        $va = $this->adValidator->all($params);
        $lists = $this->adService->allAd($va);
        return $this->success([
            'lists' => $lists,
        ]);
    }

    public function detail()
    {

    }

    public function add()
    {
        $params = $this->allParams();
        $va = $this->adValidator->add($params);
        [$r, $msg] = $this->adService->addAd($va);
        if ($r) {
            return $this->success(null, $msg);
        }
        return $this->fail($msg);
    }

    public function update()
    {
        $params = $this->allParams();
        $va = $this->adValidator->update($params);
        [$r, $msg] = $this->adService->updateAd(intval($va['id']), $va);
        if ($r) {
            return $this->success(null, $msg);
        }
        return $this->fail($msg);
    }

    public function del()
    {
        $params = $this->allParams();
        $va = $this->adValidator->del($params);
        [$r, $msg] = $this->adService->delAd($va['ids']);
        if ($r) {
            return $this->success(null, $msg);
        }
        return $this->fail($msg);
    }
}